<template>
	<view>
		<view class="idinfo margin30 bor-ra">
			<view class="address-edit">
				<view class="form bg-white">
					<u-field v-model="addressObj.real_name" label="姓名" placeholder="请填写姓名">
					</u-field>
					<u-field v-model="addressObj.mobile" label="联系方式" placeholder="请填写手机号码">
					</u-field>
					<u-field v-model="addressObj.idnum" label="身份证号" placeholder="请填写身份证号">
					</u-field>
					<view  @click="showRegion = true">
						<u-field v-model="region" :disabled="true" label="所在地区" placeholder="请选择省、市、区" right-icon="arrow-right">
						</u-field>
					</view>
					<view>
						<u-field v-model="addressObj.address" type="textarea" label="详细地址" placeholder="请填写小区、街道、门牌号等信息"
							:field-style="{flex: 1, height: '200rpx'}" />
					</view>
					<!-- 同意协议 -->
					<view class="apply-form-item flex" style="margin: 20rpx 0 0 26rpx;">
						<u-checkbox shape="circle" :active-color="colorConfig.primary" v-model="isAgree">
							<text class="sm">已阅读并同意</text>
						</u-checkbox>
						<router-link :to="{path: '/bundle/pages/server_explan/server_explan', query: {type: 5}}">
						<text class="primary sm">《入驻协议》</text>
						</router-link>
					</view>
				</view>
				<u-select v-model="showRegion" mode="mutil-column-auto" @confirm="regionChange" :list="lists"></u-select>
			</view>
		</view>
		<view class="submit-s" @tap="formSubmit">马上申请</view>
		<view class="check" @click="apifun.navigate('/bundle/pages/check/check',3)">查看提交记录</view>
	</view>
</template>
<!-- 411528199902162933 -->
<script>
	import {
		VerApply,
		levelapply
	} from '@/api/user';
	import area from '@/utils/area'
	export default {
		data() {
			return {
				addressObj: {
					real_name: '',
					mobile: '',
					idnum: '',
					province: '',
					city: '',
					district: '',
					address: '',
					is_default: false
				},
				isAgree: false,
				region: '',
				level_types:'',
				shop_user_id: '',
				showRegion: false,
				condition: [],
				lists: []
			};
		},
		onLoad: function(option) {
			// this.VerApply();
			this.$nextTick(() => {
				this.lists = area
			})
			console.log('option',option)
			this.level_types = option.level_type
			this.shop_user_id = option.shop_user_id
		},
	
		onUnload: function() {
			uni.removeStorageSync('wxAddress');
		},
	
		methods: {
			async VerApply(){
				const {
					code,
					data
				} = await VerApply()
				console.log('data',data);
				if (code == 1) {
					this.condition = data
				}
			},
			async formSubmit() {
				// if (this.condition.is_apply == 0 ) return this.$toast({
				// 	title: '您还未满足申请条件'
				// });
				let {
					addressObj: {
						real_name,
						mobile,
						idnum,
						province_id,
						city_id,
						district_id,
						is_default,
						address
					},
					addressId,
					region,
				} = this;
				if (!real_name) return this.$toast({
					title: '请填写收货人姓名'
				});
				if (!mobile) return this.$toast({
					title: '请填写手机号码'
				});
				if (!idnum) return this.$toast({
					title: '请填写身份证号'
				});
				if (!region) return this.$toast({
					title: '请选择省、市、区'
				});
				if (!address) return this.$toast({
					title: '请填写小区、街道、门牌号等信息'
				});
				if (!this.isAgree) return this.$toast({
					title: '请先同意《入驻协议》'
				})
				const params = {
					real_name,
					mobile,
					identity_card:idnum,
					province: parseInt(province_id),
					city: parseInt(city_id),
					district: parseInt(district_id),
					address,
					level_id: 3,
					level_type: this.level_types,
					shop_user_id: this.shop_user_id,
				}
				console.log('params',params)
				const {
					code,
					msg
				} = await levelapply(params)
				if (code == 1) {
					this.$toast({
						title: msg
					});
					setTimeout(()=>{
						this.apifun.navigate('/bundle/pages/check/check',3)
					},2000)
				}
			},
			regionChange(region) {
				this.addressObj.province_id = region[0].value;
				this.addressObj.city_id = region[1].value;
				this.addressObj.district_id = region[2].value;
				this.region = region[0].label + " " + region[1].label + " " + region[2].label
			},
	
			getOneAddressFun() {
				getOneAddress(this.addressId).then(res => {
					if (res.code == 1) {
						let {
							city,
							province,
							district
						} = res.data;
						this.addressObj = res.data;
						this.region = `${province} ${city} ${district}`
					}
				});
			},
		}
	};
</script>

<style>
.require{
	background-color: #FFFFFf;
	padding: 60rpx 0;
	margin-top: 14rpx;
}
.hint{
	text-align: center;
	margin-bottom: 40rpx;
	font-size: 36rpx;
	color: #585858;
}
.graderow{
	padding: 0 40rpx;
/* 	text-align: center;
	box-sizing: border-box; */
}
/* .graderow:nth-of-type(1),
.graderow:nth-of-type(2){
	border-right: #eaeaea 1rpx solid;
} */
.gradenum{
	font-size: 36rpx;
	color: #f5335e;
}
.gradetext{
	margin-top: 8rpx;
	font-size: 26rpx;
	color: #707070;
}
.idinfo{
	background-color: #fff;
	margin-top: 30rpx;
	padding: 32rpx 26rpx;
}
.title{
	margin: 20rpx 0;
}
.dian{
	color: red;
	
	margin-right: 6rpx;
}
input{
	font-size: 30rpx;
}
.submit-s{
	text-align: center;
	color: #ffffff;
	padding: 20rpx;
	font-size: 30rpx;
	border-radius: 50rpx;
	margin: 70rpx 36rpx ;
	background-color: #f5335e;
}
.check{
	text-align: center;
	padding-bottom: 50rpx;
	color: #707070;
}
</style>
